﻿using MySqlConnector;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeBuilder.Reader
{
    public class MyReader
    {
        private readonly string connectionString;

        public MyReader(string connectionString)
        {
            this.connectionString = connectionString;
        }

        public DataTable ReadTable(string sql)
        {
            MySqlDataSource dataSource = new MySqlDataSource(connectionString);
            using var conn = dataSource.CreateConnection();
                      conn.Open();
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            cmd.CommandTimeout = 1200;
            DataTable dataTable = new DataTable();
            using (MySqlDataAdapter dataAdapter = new MySqlDataAdapter(cmd))
            {
                dataAdapter.Fill(dataTable);
            }

            conn.Close();
            return dataTable;
        }
    }
}
